import json

from django.shortcuts import render, redirect
from django.http import HttpResponse,JsonResponse
# Create your views here.
from django.urls import reverse
from django.views import View


class PersonView(View):

    def get(self,request):
        person_data = {
            'name' : 'zhangsan',
            'age' : 18,
            'like' : ['play','music'],
            'sex' : 0
        }
        json_str = json.dumps(person_data)

        return HttpResponse(content=json_str)
        # JsonRespose 自动自动将dict/list 转换成字符串
        # return JsonResponse(person_data)

class IndexView(View):

    def get(self,request):
        # 重定向
        # 反向解析 reverse
        url = reverse('Person:person')
        return redirect(url)

class BookView(View):
    def get(self, request):
        return render(request, 'index.html', {'name': "模板操作"})